package com.lieve;

import com.lieve.entity.Employee;
import com.lieve.entity.Person;

import java.lang.reflect.Field;
import java.util.Vector;

/**
 * @author sunlijiang
 * @date 2020/4/25
 */
public class ClassLoaderTest {
    public static void main(String[] args) throws IllegalAccessException, NoSuchFieldException {
        // printLoadClasses(ClassLoader.getSystemClassLoader().getParent());
        // printLoadClasses(String.class.getClassLoader());
        printLoadClasses(ClassLoader.getSystemClassLoader());
        Person person = new Person();
        printLoadClasses(ClassLoader.getSystemClassLoader());
        getEmployee();
        printLoadClasses(ClassLoader.getSystemClassLoader());

    }

    private static Employee employee;

    public static void printLoadClasses(ClassLoader classLoader) throws IllegalAccessException, NoSuchFieldException {
        Field f = ClassLoader.class.getDeclaredField("classes");
        f.setAccessible(true);
        Vector vector = (Vector) f.get(classLoader);
        System.out.println(vector);
        System.out.println("+++++++++");
    }

    public static void getEmployee2() throws NoSuchFieldException, IllegalAccessException {
        printLoadClasses(ClassLoader.getSystemClassLoader());
        Employee employee = null;
        printLoadClasses(ClassLoader.getSystemClassLoader());
        return;
    }

    public static Employee getEmployee() throws NoSuchFieldException, IllegalAccessException {
        return employee;
    }
}
